package com.example.zhugenew.fragment;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mymvplibrary.ui.fragment.BaseMvpFramgent;
import com.example.zhugenew.R;
import com.example.zhugenew.adapter.RecommendAdapter;
import com.example.zhugenew.bean.RecommendBean;
import com.example.zhugenew.concation.MainConations;
import com.example.zhugenew.model.HomeModel;
import com.example.zhugenew.presenter.HomePresenter;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;


public class RecommendedFragment<T> extends BaseMvpFramgent<MainConations.MainView, HomeModel, HomePresenter<T>> implements MainConations.MainView<T> {


    @BindView(R.id.recom_recl)
    RecyclerView recomRecl;
    @BindView(R.id.smart)
    SmartRefreshLayout smart;
    private ArrayList<RecommendBean.ListBean> listBeans;
    private RecommendAdapter recommendAdapter;

    @Override
    protected HomePresenter<T> createPresenter() {
        return new HomePresenter();
    }

    @Override
    protected void initEvent() {
        recomRecl.setLayoutManager(new LinearLayoutManager(context));
        recomRecl.addItemDecoration(new DividerItemDecoration(context,DividerItemDecoration.VERTICAL));
        listBeans = new ArrayList<>();
        recommendAdapter = new RecommendAdapter(listBeans, context, R.layout.layout_recommend_item);
        recomRecl.setAdapter(recommendAdapter);
        HashMap<String, Object> map = new HashMap<>();

        map.put("pageStart", 1);
        map.put("pageLimit", 100);
        map.put("city", "bj");
        mPerter.getData("contentService/v1/News/appNewsRecommendList", 1, map);
    }

    @Override
    protected int createLayoutId() {

        return R.layout.fragment_recommended;
    }

    @Override
    public void showList(T t, int type) {
        if (type==1) {
            RecommendBean recommendBean = new Gson().fromJson((JsonElement) t, RecommendBean.class);
            listBeans.addAll(recommendBean.getList());
            recommendAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void showError(String error, int code) {

    }

    @Override
    public void showProgressbar() {

    }

    @Override
    public void hideProgressbar() {

    }
}